package test.demo;
/**
 * <P>依赖倒转示例二</P>
 * */
public class DependencyInversionNew {
    public static void main(String[] args) {
        //客户端无需改变
        PersonNew person = new PersonNew();
        person.receive(new EmailNew());
        person.receive(new WeiXinNew());
    }
}
//定义接口
interface IReceiverNew {
    public String getInfo();
}
class EmailNew implements IReceiverNew {
    public String getInfo() { return "电子邮件信息: hello,world"; }
}
//增加微信
class WeiXinNew implements IReceiverNew {
    public String getInfo() { return "微信信息: hello,ok"; }
}
//方式2
class PersonNew {
    //这里我们是对接口的依赖
    public void receive(IReceiverNew receiver ) { System.out.println(receiver.getInfo()); }
}